<?php
include_once('common/header.php');
$strRefer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if($AppUI->id <= 0 || $strRefer == '') {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intAction 	= $objRequest->getParam('act',null);
$intBlogId 	= $objRequest->getParam('blogid',null);
$intError	= 0;
$objBlog 	= new Blog();
$strMessage	= '';
$intLike	= 0;
if(isset($intAction)) {
	if($intAction == 1) {
		$intError = $objBlog->addLike($AppUI->id, $intBlogId, $intLike);		
		if($intError > 0) {
			if($intError < 3) {
				$intError += 1;
			} else {
				$intError = 27;
			}
		}
		else $strMessage = $arrMessage[1];
	}elseif($intAction == 2) {
		$intError = $objBlog->delete($AppUI->id,$intBlogId);		
		if($intError > 0) $intError = 4; 
		$strMessage = $arrMessage[2];
	}elseif($intAction == 3) {
		$intError = $objBlog->updateImg($AppUI->id,$intBlogId);
		if($intError > 0) $intError = 5; 
		$strMessage = $arrMessage[3];
	}elseif($intAction == 4) {
		$intOwnerId	= Vfriend_Function::base64D($objRequest->getParam('uid',''));		
		$intAjax 	= 1;
		include_once('blog/user.php');
		$this->view->ajax = $intAjax;
		$objView 	= Zend_Registry::get('objView');
		$strData	= $objView->fetch('blog/box-result.tpl');
		$arrJson 	= array('error'=>0,'dblog'=>$strData);
		echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
		exit();
	}elseif($intAction == 5) {
		$intOwnerId	= Vfriend_Function::base64D($objRequest->getParam('uid',''));		
		$intAjax 	= 1;
		include_once('blog/index.php');
		$this->view->ajax = $intAjax;
		$objView 	= Zend_Registry::get('objView');
		$strData	= $objView->fetch('blog/box-result.tpl');
		$arrJson 	= array('error'=>0,'dblog'=>$strData);
		echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
		exit();
	}elseif($intAction == 6) {
		$intOwnerId	= Vfriend_Function::base64D($objRequest->getParam('uid',''));		
		$intAjax 	= 1;
		include_once('blog/search.php');
		$this->view->ajax = $intAjax;
		$objView 	= Zend_Registry::get('objView');
		$strData	= $objView->fetch('blog/box-result.tpl');
		$arrJson 	= array('error'=>0,'dblog'=>$strData);
		echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
		exit();
	}
}	
if($intError == 0) {
	if($intAction == 1) {
		$arrJson	= array('error'=>0,'msg'=>$strMessage,'like'=>Vfriend_Function::numberFormat($intLike));
	} elseif($intAction > 1) {		
		$arrJson	= array('error'=>0,'msg'=>$strMessage);
	}
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';	
} else {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[$intError]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
}
exit();
?>
